//
//  MyAttractOfislanCellTableViewCell.m
//  diaoyuren
//
//  Created by 钓鱼人 on 16/4/14.
//  Copyright © 2016年 game. All rights reserved.
//

#import "MyAttractOfislanCellTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "TQStarRatingView.h"

@interface MyAttractOfislanCellTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *imageShow;


@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *titleLab;
@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *localLab;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *linHeight;
@property (weak, nonatomic) IBOutlet UIView *certenView;
@property (weak, nonatomic) IBOutlet UILabel *footShowLab;
@property (weak, nonatomic) IBOutlet MBLabelWithFontAdapter *timeLab;

@property (nonatomic,strong) TQStarRatingView *starRating;

@end

@implementation MyAttractOfislanCellTableViewCell

- (void)awakeFromNib {
    self.selectionStyle = 0;
    
    self.footShowLab.backgroundColor = tabGropBackColor;
    
    self.cancelBtn.layer.borderColor = mainColor.CGColor;
    self.cancelBtn.layer.borderWidth = 0.5;
   
    radius(self.cancelBtn, 3);
    
    self.linHeight.constant = 0.5;
}

-(void)drawRect:(CGRect)rect{

    /**
     *  添加 星星评分
     */
    CGFloat hh  = SCREEN_HEIGHT*0.024;
    CGFloat  ww =  (hh*(1.05))*5+(hh/1.5); //1.05是一个星星的宽高比
    
    CGFloat yy = (H(self.certenView)-hh)/2;
    CGFloat xx = X(self.titleLab);
    
    self.starRating = [[TQStarRatingView alloc]initWithFrame:CGRectMake(xx, yy, ww, hh)];
    [self.certenView addSubview:self.starRating];
    [self.starRating StarForegroundViewWithScore:_model.score];
}

-(void)setModel:(My_attention_diaochang_listModel *)model{
    _model = model;
    
    [self.imageShow sd_setImageWithURL:[NSURL URLWithString:_model.thum_url]];
    self.timeLab.text = _model.dateline;
    self.titleLab.text = _model.name;
    self.localLab.text = _model.location;
    self.tid = _model.tid;
    
    self.detail = _model.detail;
    self.latitude = _model.latitude;
    self.longitude = _model.longitude;
    
    self.localtion = _model.location;

}
//点击取消关注
- (IBAction)cancelAction:(MBButtonWithFontAdapter *)sender {
    
    [self getFormHash];
}

-(void)getFormHash{

    [[Manager sharedManager]RequestWhithURL:GetFormhash AndParameter:nil AndCompletionType:^(id responseObject, DIEError *error) {
        if ([responseObject[@"status"] isEqualToString:@"SUCCESS"]) {

            [self  cancelWhithFormhash:responseObject[@"data"][@"formhash"]];
        
        }
    }];
}

-(void)cancelWhithFormhash:(NSString *)formHash{
        
    NSDictionary *dic = @{
                          @"formhash":formHash,
                          @"d_id":self.model.tid,
                          @"module":self.module,
                          @"y_id":self.model.tid
                          };
    
    [[Manager sharedManager]ResponseWhithURL:CancelMyAttractIslan AndParameter:dic AndCompletionType:^(id responseObject, DIEError *error) {
        
        if ([responseObject[@"status"] isEqualToString:@"SUCCESS"]) {//删除请求成功代理传递到控制器，是TableView实现本地删除数据
        
            if ([_deleget respondsToSelector:@selector(CancelClickWhithCell:)]) {
                [self.deleget CancelClickWhithCell:self];
            }
        }else{
        

        }
    }];

}

@end
